package com.jiayou.Map;

import com.jiayou.Tank.Model;
import com.jiayou.Tank.Tank1;
import com.jiayou.tools.Constclass;
import com.jiayou.tools.TheGameLoading;

import java.awt.*;
import java.util.List;

public class Zhuan extends Body {
    private Image image;

    public Zhuan(int x, int y, int width, int heigh) {
        super(x, y, width, heigh);
        this.image = TheGameLoading.getImage("zhuan.png");
    }

    public void draw(Graphics graphics, Tank1 tank1) {
        graphics.drawImage(image, x, y, width, heigh, null);
        if (super.rec().intersects(tank1.rec())) {
            if (tank1.left) {
//                tank1.can_left = false;
                tank1.x += 2;
            }
            if (tank1.right) {
//                tank1.can_right = false;
                tank1.x -= 2;
            }
            if (tank1.up) {
//                tank1.can_up = false;
                tank1.y += 2;
            }
            if (tank1.down) {
//                tank1.can_down = false;
                tank1.y -= 2;
            }
            System.out.println("碰到了");
        }

    }

    @Override
    public void drawdiren(List<Model> list) {
        for (Model model : list) {
            if (super.rec().intersects(model.rec())) {
                if (model.sw == Constclass.LEFT) {
//                tank1.can_left = false;
                    model.x += 3;
                    model.sw = Constclass.RIGHT;
                    break;
                }
                if (model.sw == Constclass.RIGHT) {
//                tank1.can_right = false;
                    model.x -= 3;
                    model.sw = Constclass.LEFT;
                    break;
                }
                if (model.sw == Constclass.UP) {
//                tank1.can_up = false;
                    model.y += 3;
                    model.sw = Constclass.DOWN;
                    break;
                }
                if (model.sw == Constclass.DOWN) {
//                tank1.can_down = false;
                    model.y -= 3;
                    model.sw = Constclass.UP;
                    break;
                }
            }
        }
    }
}
